package com.cms.work.shiro;

import org.apache.log4j.Logger;
import org.apache.shiro.authz.Permission;
import org.apache.shiro.util.AntPathMatcher;
import org.apache.shiro.util.PatternMatcher;

/**
 * <p>Title: UrlPermission</p>
 * <p>Description: 根据Url串判断权限是否满足</p>
 * <p>Email: yuyue_qty@163.com</p>
 * @author 晴天雨
 * @date 2016年2月2日下午5:14:29
 * @version 1.0
 */
public class UrlPermission implements Permission{
    
    private static Logger logger = Logger.getLogger(UrlPermission.class);

	private String url;
	
	public UrlPermission() {
	}
	
	public UrlPermission(String url) {
		this.url = url;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
	@Override
	public boolean implies(Permission p) {
		if(!(p instanceof UrlPermission)) return false;
		UrlPermission up = (UrlPermission) p;
		PatternMatcher patternMatcher = new AntPathMatcher();
//		logger.info(this.url + "," + up.getUrl() + "," + patternMatcher.matches(this.url, up.getUrl()));
		return patternMatcher.matches(this.url, up.getUrl());
	}
	
}
